// 个人中心页面逻辑
const userApi = require('../../api/userApi');
const essayApi = require('../../api/essayApi');
const app = getApp();

Page({
  data: {
    userInfo: {},
    points: 0,
    historyList: [],
    loading: false
  },

  onLoad: function (options) {
    // 页面初始化
  },
  
  onShow: function () {
    // 获取用户信息
    this.setData({
      userInfo: app.globalData.userInfo || {},
      points: app.globalData.points || 0
    });
    
    // 获取批改历史
    this.getHistory();
  },
  
  // 获取批改历史
  getHistory: function () {
    if (this.data.loading) return;
    
    this.setData({ loading: true });
    
    essayApi.getCorrectionHistory(1, 3)  // 只获取最近3条
      .then(result => {
        this.setData({
          historyList: result.list || []
        });
      })
      .catch(err => {
        console.error('获取批改历史失败', err);
      })
      .finally(() => {
        this.setData({ loading: false });
      });
  },
  
  // 跳转到批改详情
  goToDetail: function (e) {
    const id = e.currentTarget.dataset.id;
    
    wx.navigateTo({
      url: `/pages/correction/correction?id=${id}`
    });
  },
  
  // 查看更多批改历史
  viewMore: function () {
    wx.navigateTo({
      url: '/pages/history/history'
    });
  },
  
  // 跳转到消息通知页面
  goToNotifications: function () {
    wx.navigateTo({
      url: '/pages/notifications/notifications'
    });
  },
  
  // 跳转到隐私设置页面
  goToPrivacy: function () {
    wx.navigateTo({
      url: '/pages/privacy/privacy'
    });
  },
  
  // 跳转到帮助与反馈页面
  goToHelp: function () {
    wx.navigateTo({
      url: '/pages/help/help'
    });
  },
  
  // 跳转到关于我们页面
  goToAbout: function () {
    wx.navigateTo({
      url: '/pages/about/about'
    });
  }
}); 